package org.ricks.orm.mongodb;

import com.mongodb.client.model.Updates;
import org.bson.conversions.Bson;
import java.util.List;

/**
 * @Author ricks [chenwei]
 * @Version [v1.0]
 * @CreateTime 2024-06-07   18:29
 * @Description TODO
 */
public class OrmContext {

    public static Bson update(String info,Object... args) {
        return analysis(info, args);
    }


    public static void main(String[] args) {
        String a = "items.{}.bags.{}.count";
        Bson bson = analysis(a, List.of(1,2),2);
        System.err.println(bson);
    }

    public static Bson analysis(String mongoStr, Object... args) {
        int index = 0;
        while (mongoStr.contains("{}")) {
            Object o = args[index];
            index ++;
            String str = String.valueOf(o);
            mongoStr = mongoStr.replaceFirst("\\{}", str);
        }
        System.err.println(mongoStr);
        return Updates.set(mongoStr,args[index]);
    }
}
